#include <avr/io.h>
#include "lcd_graph.h"

void low_init(void)
{
	DDR_LCD_E_RD|=1<<LCD_E_RD;
	DDR_LCD_CS|=1<<LCD_CS;
	DDR_LCD_RW|=1<<LCD_RW;
	DDR_LCD_DC|=1<<LCD_DC;
	DDR_LCD_RES|=1<<LCD_RES;
}

void delay(void)
{
 short i;
 for(i=0;i<100;i++) asm("nop");
};


void Init_lcd(void)
{
	low_init();
	LCD_RES_HIGH;
	LCD_RES_LOW;
	delay();
	LCD_RES_HIGH;
	LCD_RES_LOW;
	delay();
	LCD_RES_HIGH;
}

void write_comannd(unsigned char cmd)
{

DDR_LCD_DATA =0xff;

LCD_CS_LOW;

	LCD_DC_LOW;LCD_E_RD_HIGH;;

	LCD_RW_LOW;
		PORT_LCD_DATA=cmd;
	LCD_RW_HIGH;

LCD_CS_HIGH;
}


unsigned char read_status(void)
{
unsigned char tmp;

DDR_LCD_DATA =0x00;

LCD_CS_LOW;

	LCD_DC_LOW;LCD_WR_HIGH;

	LCD_E_RD_LOW;
		tmp=PIN_LCD_DATA;
	LCD_E_RD_HIGH;

LCD_CS_HIGH;
}

unsigned char read_data(void)
{
unsigned char tmp;

DR_LCD_DATA =0x00;

LCD_CS_LOW;

	LCD_DC_HIGH;LCD_WR_HIGH;

	LCD_E_RD_LOW;
		tmp=PIN_LCD_DATA;
	LCD_E_RD_HIGH;

LCD_CS_HIGH;

return tmp;
}

void write_data(unsigned char data)
{
DDR_LCD_DATA =0xff;

LCD_CS_LOW;

	LCD_DC_HIGH;LCD_E_RD_HIGH;

	LCD_RW_LOW;
		PORT_LCD_DATA=data;
	LCD_RW_HIGH;

LCD_CS_HIGH;
};


